package com.dingding.nettyserver.core.queue;

import java.util.Properties;

import org.apache.log4j.Logger;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.dingding.common.core.config.Constants;
import com.dingding.common.core.config.MessageQueueConfig;
import com.dingding.common.core.config.SystemConfig.TagsEnum;
import com.dingding.nettyserver.core.queue.listener.NettyPushListener;

/**
 * @Description tcp推送的消费者
 * @author fengshuonan
 * @date 2016年11月30日 下午11:22:01
 */
public class NettyPushConsumer{

	private Logger log = Logger.getLogger(NettyPushConsumer.class);

	private NettyPushListener nettyPushListener;

	public void intital() {
		try {
			log.info("正在订阅tcp推送主题！");
			Properties properties = new Properties();
			properties.put(PropertyKeyConst.ConsumerId,MessageQueueConfig.getMESSAGE_QUEUE_NETTY_PUSH_CONSUMERID());
			properties.put(PropertyKeyConst.AccessKey, Constants.MESSAGE_QUEUE_ACCESSKEY);
			properties.put(PropertyKeyConst.SecretKey, Constants.MESSAGE_QUEUE_SERECTKEY);
			Consumer consumer = ONSFactory.createConsumer(properties);
			consumer.subscribe(MessageQueueConfig.getMESSAGE_QUEUE_TOPIC(), TagsEnum.NETTY_PUSH.toString(),nettyPushListener);
			consumer.start();
		} catch (Exception e) {
			log.error("订阅tcp推送出现异常！PushConsumer:intital()", e);
		}
	}

	public NettyPushListener getNettyPushListener() {
		return nettyPushListener;
	}

	public void setNettyPushListener(NettyPushListener nettyPushListener) {
		this.nettyPushListener = nettyPushListener;
	}

}
